package com.bcu.calculus.service.serviceImpl;

import com.bcu.calculus.entity.Message;
import com.bcu.calculus.entity.User;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.bcu.calculus.mapper.BranchMapper;
import com.bcu.calculus.entity.Branch;
import com.bcu.calculus.service.BranchService;

import java.util.List;

@Service
public class BranchServiceImpl implements BranchService{

    @Resource
    private BranchMapper branchMapper;

    @Override
    public Message<?> add(Branch record) {
        Branch u = branchMapper.selectByPrimaryKey(record.getBranchId());
        if (u == null) {
            return branchMapper.insertSelective(record) > 0 ? Message.success(null) : Message.fail(null);
        } else {
            return Message.fail("党小组id已经存在");
        }
    }

    @Override
    public Message<?> del(Integer branchId) {
        return branchMapper.deleteByPrimaryKey(branchId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> update(Branch record) {
        return branchMapper.updateByPrimaryKeySelective(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<List<Branch>> selectAll() {
        return Message.success(null).add(branchMapper.selectByAll());
    }

    @Override
    public Message<Branch> selectByPK(Integer branchId) {
        return Message.success(null).add(branchMapper.selectByPrimaryKey(branchId));
    }
}
